package top.chengdongqing.mishop.order.review.vo

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import top.chengdongqing.mishop.entities.OrderReview
import java.io.Serializable

data class OrderReviewVO(
    val orderId: Int,
    val packagingRating: Int?,
    val speedRating: Int?,
    val serviceRating: Int?,
    val content: String?,
    val photoUrls: List<String>?,
    val isAnonymous: Boolean?,
    val items: List<ProductReviewVO>
) : Serializable {
    companion object {
        fun of(review: OrderReview, items: List<ProductReviewVO>): OrderReviewVO {
            return OrderReviewVO(
                orderId = review.orderId,
                packagingRating = review.packagingRating,
                speedRating = review.speedRating,
                serviceRating = review.serviceRating,
                content = review.content,
                photoUrls = review.photoUrls?.let {
                    jacksonObjectMapper().readValue(it)
                },
                isAnonymous = review.isAnonymous,
                items = items
            )
        }
    }
}
